var leaguebuttone = "true";
var teambuttone = "true";

function getSeasons(parent,object)
{
	if(object.value==-1)
	{
		$('seasondiv').update('');
	}
	else
	{
	   	new Ajax.Request('/ajax/admin_ajax.php',
	   	{
	      	method: 'post',
	      	parameters: {action: 'seasons', leagueid: object.value},
	      	onComplete:function(transport) {
	      		$('seasondiv').update(transport.responseText);
	      		
	      	}
	   	}); 	
	}
}

function getLeagueSearch()
{
	if(leaguebuttone=="true")
	{
		leaguebuttone = "false";
		//$('leaguebutton').addClassName('buttondisable').show();
		$('leaguebutton').disabled = true;
		new Ajax.Request('/ajax/admin_ajax.php',
		{
		    method: 'post',
		    parameters: {action: 'getleaguesearch', search: $('leaguesearch').getValue()},
		    onComplete:function(transport) {
		    	//$('leaguebutton')..removeClassName('buttondisable').show();
		    	$('leaguebutton').disabled = false;
		    	leaguebuttone = "true";
		     	document.getElementById('leaguesearchrow').className="featInfoChunk";
		     	$('leaguerow').show();
		     	if(transport.responseText=='')
		     	{
		     		$('leaguediv').update("<div class='failure'>No leagues were found that matched the specified search string.  Try again.</div>");	
		     		$('leaguetitlediv').update('');
		     	}
		     	else
		     	{
		      		$('leaguediv').update(transport.responseText);
		      		$('leaguetitlediv').update('Select Your League: ');
		     	}
		 }}); 	
	}
}

function getDivisionsFromSeason(parent,object)
{
	if(object.value==-1)
	{
		$('teamdivisiondiv').update('');
		$('teamdivisionrow').hide();
	}
	else
	{
		new Ajax.Request("/ajax/admin_ajax.php",
		{
			method: 'post',
			parameters: {action: 'divisionfromseason', seasonid: object.value},
			onComplete: function(transport)
			{
				document.getElementById('seasonrow').className = "featinfoChunk";
				$('teamdivisionrow').show();
				$('teamdivisiondiv').update(transport.responseText);
			}
		});
	}
}

function getDivisionsCaptain(parent,object)
{
	if(object.value==-1)
	{
		$('teamdivisiondiv').update('');
		$('teamdivisionrow').hide();
	}
	else
	{
		new Ajax.Request("/ajax/admin_ajax.php",
		{
			method:'post',
			parameters: {action: 'divisioncaptain', leagueid: object.value},
			onComplete:function(transport)
			{
				var text = transport.responseText.evalJSON(true);
				if(text.type == "multiple")
				{
					document.getElementById('leaguerow').className="featinfoChunk";
					$('seasonrow').show();
					$('teamdivisionrow').hide();
					$('seasondiv').update(text.data);
				}
				else
				{
					document.getElementById('leaguerow').className="featinfoChunk";
					$('teamdivisionrow').show();
					$('seasonrow').hide();
					$('teamdivisiondiv').update(text.data);
				}
			}
		});
	}
}

function getTeamsCaptain(parent,object,seasonid)
{	
	if($('join').getValue()=='join')
	{
		var join = 1;
	}
	else
	{
		var join = 0;
	}
	if(object.value==-1)
	{
		$('teamdiv').update('');
		$('teamrow').hide();
	}
	else
	{
		new Ajax.Request("/ajax/admin_ajax.php",
		{
			method: 'post',
			parameters: {action: 'teamscaptain', divisionid: object.value, seasonid: $('seasonid').getValue(),join: join},
			onComplete: function(transport)
			{
				document.getElementById('teamdivisionrow').className="featinfoChunk";
				$('teamrow').show();
				$('teamdiv').update(transport.responseText);
				$('teamtitlediv').update('Choose Your Team: ');
			}
		}
		);
	}
}
//Search for the Team by wildcard
function getTeamSearch()
{
	if($('join').getValue()=='join')
	{
		var join = 1;
	}
	else
	{
		var join = 0;
	}
	if(teambuttone=="true")
	{
		teambuttone="false";
		$('teambutton').disabled = true;
		new Ajax.Request("/ajax/admin_ajax.php",
		{
			method: 'post',
			parameters: {action: "getteamsearch", leagueid: $('leagueidhidden').getValue(), teamsearch: $('teamsearch').getValue(), join:join},
			onComplete: function(transport)
			{
				teambuttone = "true";
				$('teambutton').disabled = false;
				document.getElementById('teamdivisionrow').className="featinfoChunk";
				$('teamrow').show();
				if(transport.responseText=='')
				{
					$('teamdiv').update("<div class='failure'>No teams were found that matched the specified search string. Try again</div>");
					$('teamtitlediv').update('');
				}
				else
				{
					$('teamdiv').update(transport.responseText);
					$('teamtitlediv').update('Choose Your Team: ');
				}
			}
		}
		);
	}
}
function selectTeam(parent,object)
{
	window.location = "captain_request_team.php?teamid=" + object.value;
}
function saveandsend(teamids)
{
	//explode
	var arr = teamids.split(";");
	var update = "";
	var updateids = "";
	var teamnames = "";
	var contactnames = "";
	for(i=0;i<arr.length;i++)
	{
		if(arr[i]=="")
		{
			
		}
		else
		{
			var val = $('team' + arr[i]).getValue();
			var contact = $('teamcontact' + arr[i]).getValue();
			if(val=="")
			{
				
			}
			else
			{
				update += val + ";";
				updateids += arr[i] + ";";
				var teamname = 'name' + arr[i];
				teamnames += $(teamname).getValue() + ";";
				contactnames += contact + ";";
				$('team' + arr[i]).hide();
				$('teamcontact' + arr[i]).hide();
				$('div' + arr[i]).update(val);
				$('div' + arr[i]).show();
				$('contactdiv'+arr[i]).update(contact);
				$('contactdiv'+arr[i]).show();
				$('editdiv' + arr[i]).show();
				$('edit' + arr[i]).show();
				$('cancel' + arr[i]).hide();
			}
		}
	}
	new Ajax.Request('/ajax/admin_ajax.php',
		{
	      	method: 'post',
	      	parameters: {action: 'update', emails: update, ids: updateids, names: teamnames, contacts: contactnames},
	      	onComplete:function(transport) {
	      	}
	   	}); 
}

function editAddress(teamid)
{
	$('div' + teamid).hide();
	$('team' + teamid).show();
	$('contactdiv' + teamid).hide();
	$('teamcontact' + teamid).show();
	$('edit' + teamid).hide();
	$('cancel' + teamid).show();
}

function cancelEdit(teamid)
{
	$('div' + teamid).show();
	$('team' + teamid).hide();
	$('contactdiv' + teamid).show();
	$('teamcontact' + teamid).hide();
	$('edit' + teamid).show();
	$('cancel' + teamid).hide();
}

function submitRegister()
{
	var fname = $('fname').getValue();
	var lname = $('lname').getValue();
	var accept = $('acceptcheck').getValue();
	var e = $('email').getValue();
	var t = $('teamid').getValue();
	var n = $('tname').getValue();
	var superorgid = $('superorgid').getValue();
	var templatename = $('templatename').getValue();
	if($('password1'))
	{
		var p1 = $('password1').getValue();
		var p2 = $('password2').getValue();
	}
	else
	{
		var p1 = '';
		var p2 = '';
	}
	if(fname==""||lname=="")
	{
		onFailure("You must specify a first and last name");
	}
	else if(accept==null)
	{
		onFailure("You must accept the terms and conditions of use");
	}
	else if(e=="")
	{
		onFailure("You must input a valid email address");
	}
	else if(p1!=''&&p2!=''&&p1!=p2)
	{
		onFailure("Passwords do not match");
	}
	else
	{
		//send an ajax request
		new Ajax.Request('/ajax/admin_ajax.php',
		{
	      	method: 'post',
	      	parameters: {action: 'verify', firstname: fname, lastname: lname, email: e,teamid: t,teamname: n, password: p1,superorgid: superorgid, templatename: templatename},
	      	onComplete:function(transport) {
	      		var text = transport.responseText;
	      		if(text == "false")
	      		{
	      			onFailure("The provided registration code did not match the one specified for this team in the database");
	      		}
	      		else
	      		{
	      			$('maindiv').update("");
	      			$('successdiv').update(text);
	      			$('successdiv').show();
	      			$('addressdiv').show();
	      		}
	      	}
	   	}); 
	}
}

function joinTeam() {

	var fname = $('firstname').getValue();
	var lname = $('lastname').getValue();
	var personemail = $('personemail').getValue();
	var password = $('password').getValue();
	var confirmpassword = $('confirmpassword').getValue();	
	var accesscode = $('accesscode').getValue();
	var verificationcode = $('verificationcode').getValue();
	var formdata = $('jointeamform').serialize();
	
	if (fname.blank() || lname.blank() || personemail.blank() || password.blank() || confirmpassword.blank() || accesscode.blank() || verificationcode.blank()) {
		alert("Please fill in all fields.");
		return false;
	}
	
   	new Ajax.Request('/ajax/admin_ajax.php',
   	{
    	onCreate: function () {
	    $('submitbutton').disabled = true;
	    $('submitbutton').addClassName('buttondisable').show();
       	},
     	onComplete: function() {
   	  	$('submitbutton').disabled = false;
   	  	$('submitbutton').removeClassName('buttondisable').show();
      	},      		
      	method: 'post',
 		parameters: formdata,
      	failure:'errors',
      	onSuccess:function(transport) {
        	var json = transport.responseText.evalJSON(true);
			var errormsg = json.errormessage;
		    
			if (errormsg == null) {
				
				$('status').removeClassName('failure').show();
				$('publicform').update(json.successmessage);
				$('publicform').addClassName('publicformwrapper').show();
				$('jointeamform').reset();
			} else {
				//error
				
				$('status').addClassName('failure').show();
				
				$('status').update(errormsg);
				$('status').show();
			}
      	}
   	}); 	
   		
}

function submitPlayerSignup()
{
	var e = $('personemail').getValue();
	var f = $('firstname').getValue();
	var l = $('lastname').getValue();
	var p = $('teampassword').getValue();
	var tid = $('teamid').getValue();
	var tname = $('tname').getValue();
	var verificationcode = $('verificationcode').getValue();
	
	if(e=='')
	{
		onFailure("Must input an email address");
	}
	else if(f==''||l=='')
	{
		onFailure("Must input both a first and last name");
	}
	else if(p == '')
	{
		onFailure("Must input the team password");
	}
	else
	{
		new Ajax.Request('/ajax/admin_ajax.php',
		{
			method: 'post',
			parameters: {action: 'playersignup', email: e, firstname: f, lastname: l, teamid: tid, teamname: tname, verificationcode: verificationcode, password: p, teamname: tname},
			onComplete: function(transport) {
				var text = transport.responseText;
				var json = text.evalJSON(true);
				var vf = json.verificationfailure;
				
				if(vf && vf.length>0)
				{
					onFailure(json.verificationfailure);
				} else {
					if(json.failure=="false")
					{
						onFailure(json.failuretext);
					}
					else if(json.failure == "email")
		      		{
		      			onFailure("Inputted email address does not appear to be valid");
		      		}
		      		else if(json.failure == 'name')
		      		{
		      			onFailure("Must input both a first and last name");
		      		}
					else
					{
						$('successdiv').update(json.success);
		      			$('successdiv').show();
		      			$('maindiv').hide();
					}
				}
			}
		});
	}
}

function submitCaptainRequest()
{
	var e = $('personemail').getValue();
	var f = $('firstname').getValue();
	var l = $('lastname').getValue();
	var tid = $('teamid').getValue();
	var tname = $('tname').getValue();
	var verificationcode = $('verificationcode').getValue();
	
	if(e=='')
	{
		onFailure("Must input an email address");
	}
	else if(f==''||l=='')
	{
		onFailure("Must input both a first and last name");
	}
	else
	{
		new Ajax.Request('/ajax/admin_ajax.php',
		{
	      	method: 'post',
	      	parameters: {action: 'captainrequest', email: e, firstname: f, lastname: l, teamid: tid, teamname: tname,verificationcode: verificationcode, superorgid: $('superorgid').getValue(), templatename: $('templatename').getValue() },
	      	onComplete:function(transport) {
	      		var text = transport.responseText;
	      		var json = text.evalJSON(true);
	      		var vf = json.verificationfailure;
	      	
	      		if (vf && vf.length > 0) {
	      			
	      			onFailure(json.verificationfailure);
	      		
	      		} else {
	      			
		      		if(json.failure=="false")
		      		{
		      			onFailure("A captain has already registered for the specified team");
		      		}
		      		else if(json.failure == "email")
		      		{
		      			onFailure("Inputted email address does not appear to be valid");
		      		}
		      		else if(json.failure == 'name')
		      		{
		      			onFailure("Must input both a first and last name");
		      		}
		      		else
		      		{
		      			if(json.shithitthefan!="1")
		      			{
		      				$('failuredivreg').update(json.shithitthefan);
							$('failuredivreg').show();
		      			}
		      			else
		      			{
		      				$('successdiv').update(json.success);
		      				$('successdiv').show();
		      			}
		      			$('maindiv').hide();
		      		}
	      		}
	      	}
	   	});
	}
}

function sendCaptainEmail()
{
	var email = $('captainemail').getValue();
	var message = document.emailForm.captainmessage.value;
	var firstname = $('firstname').getValue();
	var lastname = $('lastname').getValue();
	var tid = $('teamid').getValue();
	if(message=='')
	{
		var message = $('captainmessage').getValue();
	}
	if(email==''||!verifyEmail(email))
	{
		onFailure("Email Address is not valid");
	}
	else if(firstname==''||lastname=='')
	{
		onFailure("Please input your fullname");
	}
	else
	{
		new Ajax.Request('/ajax/admin_ajax.php',
		{
		     method: 'post',
		      parameters: {action: 'captainemail', email: email, message: message , teamid: tid, lastname: lastname, firstname: firstname },
		      onComplete:function(transport) {
		      	var text = transport.responseText;
		      	onSuccess("Message successfully sent");
		      }
		}); 
	}
}

function sendSupportEmail()
{
	var email = $('captainemail').getValue();
	var message = document.emailForm.captainmessage.value;
	var firstname = $('firstname').getValue();
	var lastname = $('lastname').getValue();
	var tid = $('teamid').getValue();
	if(message=='')
	{
		var message = $('captainmessage').getValue();
	}
	if(email==''||!verifyEmail(email))
	{
		onFailure("Email Address is not valid");
	}
	else if(firstname==''||lastname=='')
	{
		onFailure("Please input your fullname");
	}
	else
	{
		new Ajax.Request('/ajax/admin_ajax.php',
		{
		     method: 'post',
		      parameters: {action: 'supportemail', email: email, message: message , teamid: tid, lastname: lastname, firstname: firstname },
		      onComplete:function(transport) {
		      	var text = transport.responseText;
		      	onSuccess("Message was sent successfully.  You should hear from Pointstreak.net support shortly.  Thank you.");
		      }
		}); 
	}
}
function verifyEmail(email)
{
	if(email.lastIndexOf("@")<0)
	{
		return false;
	}
	else if(email.lastIndexOf(".")<0)
	{
		return false;
	}
	else
	{
		return true;
	}

}

function conflictYes()
{
	var url = $('requesturl').getValue();
	window.location = url + "&flag=true";	
}

function onSuccess(message)
{
	$('successdiv').update(message);
	$('successdiv').show();
	$('failurediv').hide();	
	setTimeout("$('successdiv').style.display='none'",5000);
}

function onFailure(message)
{
	$('failurediv').update(message);
	$('failurediv').show();
	$('successdiv').hide();	
}

function sendToAdmin() {
	
	var emailsubject = $('emailsubject').getValue();
	var emailbody = $('emailbody').getValue();
	var emailcountry = $('emailcountry').getValue();
	
	if (emailsubject.blank() || emailbody.blank()) {
		alert('Both fields required.')
		return false;
	}
	
   	new Ajax.Request('/ajax/admin_ajax.php',
   	{  
   		
		onCreate: function () {	
		$('emailbody').disabled = true;
		$('sendtoadminbutton').addClassName('buttondisable').show();
		},
		onComplete: function() {
	  	$('emailbody').disabled = false;
	  	$('sendtoadminbutton').removeClassName('buttondisable').show();
	  	$('sendtoadminbutton').enable();
	  	$('emailbody').clear();
		},     		 		
      	method: 'post',
      	parameters: {action: 'sendemailtoadmins',
      				 emailsubject: emailsubject,
      				 emailbody: emailbody,
      				 emailcountry: emailcountry},
      	failure:'errors',
      	onSuccess:function(transport) {
        	var json = transport.responseText.evalJSON(true);
         	status = json.status
        
         	$('success').update(status);
         	$('success').show();
         	$('emailsubject').clear();
         	$('emailbody').clear();
         	setTimeout("$('success').style.display='none'",5000);
         	
      	}
      
   	}); 
	   		
}

function sendToEveryOne() {
	
	var emailsubject = $('emailsubject').getValue();
	var emailbody = $('emailbody').getValue();
	var emailcountry = $('emailcountry').getValue();
	
	if (emailsubject.blank() || emailbody.blank()) {
		alert('Both fields required.')
		return false;
	}
	
   	new Ajax.Request('/ajax/admin_ajax.php',
   	{  
   		
		onCreate: function () {	
		$('emailbody').disabled = true;
		$('sendtoadminbutton').addClassName('buttondisable').show();
		},
		onComplete: function() {
	  	$('emailbody').disabled = false;
	  	$('sendtoadminbutton').removeClassName('buttondisable').show();
	  	$('sendtoadminbutton').enable();
	  	$('emailbody').clear();
		},     		 		
      	method: 'post',
      	parameters: {action: 'sendemailtoeveryone',
      				 emailsubject: emailsubject,
      				 emailbody: emailbody,
      				 emailcountry: emailcountry},
      	failure:'errors',
      	onSuccess:function(transport) {
        	var json = transport.responseText.evalJSON(true);
         	status = json.status
        
         	$('success').update(status);
         	$('success').show();
         	$('emailsubject').clear();
         	$('emailbody').clear();
         	setTimeout("$('success').style.display='none'",5000);
         	
      	}
      
   	}); 
   		
}

function syncAll(overwrite) {
	new Ajax.Request('/ajax/admin_ajax.php',
   	{   		
      	method: 'post',
      	parameters: {action: 'syncall',
      				 overwrite: overwrite},
      	onSuccess:function(transport) {
        	var json = transport.responseText.evalJSON(true);
         	var status = json.status
         	if(status=="true")
         	{
         		$('syncall').update(json.data);
         	}
         	else
         	{
         		$('syncall').update("<div class='failure'>An error occurred while syncing</div>");
         	}
      	}
      
   	});
}
function overwriteSync(teamid) {
	syncTeam(teamid, 1);
}
function syncTeam(tid, overwrite) {
	var teamid;
	if(tid==-1) {
		teamid = $('teamid').getValue();
	} else {
		teamid = tid;
	}
   	new Ajax.Request('/ajax/admin_ajax.php',
   	{   		
      	method: 'post',
      	parameters: {action: 'syncteam',
      				 teamid: teamid,
      				 overwrite: overwrite},
      	onSuccess:function(transport) {
      		alert(transport.responseText);
        	var json = transport.responseText.evalJSON(true);
         	var status = json.status
         	if(status=="true")
         	{
         		$('teamresult').update(json.data);
         	}
         	else
         	{
         		$('teamresult').update("<div class='failure'>A team with the specified TeamID does not exist on Pointstreak.net</div>");
         	}
      	}
      
   	});
}
/**
	Find a team with a given TeamID
*/
function findTeam()
{
	var teamid = $('teamid').getValue();
   	new Ajax.Request('/ajax/admin_ajax.php',
   	{   		
      	method: 'post',
      	parameters: {action: 'findteam',
      				 teamid: teamid},
      	onSuccess:function(transport) {
        	var json = transport.responseText.evalJSON(true);
         	var status = json.status
         	if(status=="true")
         	{
         		$('teamresult').update(json.data);
         	}
         	else
         	{
         		$('teamresult').update("<div class='failure'>A team with the specified TeamID does not exist on Pointstreak.net</div>");
         	}
      	}
      
   	}); 	
}

function chalkBoardAllTeams() {
	
	var chalkboardbody = $('chalkboardbody').getValue();
	
	if (chalkboardbody.blank()) {
		alert('Don\'t be a loser.. fill in the body.')
		return false;
	}
	
   	new Ajax.Request('/ajax/admin_ajax.php',
   	{  
   		
		onCreate: function () {	
		$('chalkboardbody').disabled = true;
		$('sendbutton').addClassName('buttondisable').show();
		},
		onComplete: function() {
	  	$('chalkboardbody').disabled = false;
	  	$('sendbutton').removeClassName('buttondisable').show();
	  	$('sendbutton').enable();
	  	$('chalkboardbody').clear();
		},     		 		
      	method: 'post',
      	parameters: {action: 'chalkboardadmin',
      				 chalkboardbody: chalkboardbody
      				 },
      	failure:'errors',
      	onSuccess:function(transport) {
        	var json = transport.responseText.evalJSON(true);
         	status = json.status
        
         	$('success').update(status);
         	$('success').show();
         	$('chalkboardbody').clear();
         	setTimeout("$('success').style.display='none'",5000);
         	
      	}
      
   	}); 
	   		
}


function SearchForTeam() {
	
	var teamname = $('teamname').getValue();
	
	teamname = trim(teamname);
	
	if (teamname.blank()) return false;
	
	if (teamname.length < 3) {
		alert("The search must be 3 characters or more.");
		return false;
	}
	
	new Ajax.Request('/ajax/admin_ajax.php',
   	{
      	onCreate: function () {
      	$('searching').show();	
	    $('searchteambutton').disabled = true;
	    $('searchteambutton').addClassName('buttondisable').show();
       	},
     	onComplete: function() {
     	$('searching').hide();
   	  	$('searchteambutton').disabled = false;
   	  	$('searchteambutton').removeClassName('buttondisable').show();
      	},     		
      	method: 'post',
      	parameters: {action: 'search',
      				 teamname: teamname
      				 },
      	failure:'errors',
      	insertion: Insertion.Top,
      	onSuccess:function(transport) {
         	var json = transport.responseText.evalJSON(true);
         	m = json.content;
         	$('teamlistresults').show(); 	  
         	$('teamlistresults').update(m);	
      	}
   	}); 
   		
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function choosePlayerTeamOption() {
	
	var menuselection = $('playerteammenu').getValue();
	
	if (menuselection.blank()) return false;
	
	new Ajax.Request('/ajax/admin_ajax.php',
   	{		
      	method: 'POST',
      	parameters: {action: 'playerteam',
      				 menuselection: menuselection
      				 },
      	failure:'errors',
      	insertion: Insertion.Top,
      	onSuccess:function(transport) {
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;  
         	$('maincontent').update(html);	

      	}
   	}); 	

}

function menuSelection(t) {
	
	var type = t;
		
	new Ajax.Request('/ajax/admin_ajax.php',
   	{		
      	method: 'POST',
      	parameters: {action: 'submenuselection',
      				 menuselection: type
      				 },
      	failure:'errors',
      	insertion: Insertion.Top,
      	onSuccess:function(transport) {
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;  
         	$('subcontent').update(html);	

      	}
   	});
   		
}

function chooseWinner() {
		
	var formdata = $('theform').serialize();
	
	new Ajax.Request('/ajax/admin_ajax.php',
	{
		method: 'post',
		parameters: formdata,
		onSuccess: function(transport){
			var json = transport.responseText.evalJSON(true);
			
			html = json.html;
			$('status').show();
			$('status').update(html);	
		  						
		}
	});	
		
}

function findPlayerStats(playerid) {
	
	new Ajax.Request('/ajax/admin_ajax.php',
   	{		
      	method: 'POST',
      	parameters: {action: 'findplayerstats',
      				 playerid: playerid
      				 },
      	failure:'errors',
      	insertion: Insertion.Top,
      	onSuccess:function(transport) {
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;  
         	
         	p = $('playerstat_' + playerid);
         	$(p).update(html);	

      	}
   	});	
	
}

function showGamerTagPopUp(cid,pid) {
	Dialog.alert({url: "/ajax/usermanagement_ajax.php?action=gamertagpopup", options: {method: 'GET'}}, {className: "alphacube", width:250, height:220, okLabel: "Close",buttonClass: "button", zIndex:1000});	
}

function addGamerTag() {
	
	var gamertag = $('gamertag').getValue();
	
	if (gamertag.blank()) return false;
	
	new Ajax.Request('/ajax/usermanagement_ajax.php',
   	{		
      	method: 'POST',
      	parameters: {action: 'addgamertag',
      				 gamertag: gamertag
      				 },
      	failure:'errors',
      	insertion: Insertion.Top,
      	onSuccess:function(transport) {
         	var json = transport.responseText.evalJSON(true);
         	status = json.status;  
         	message = json.message;
         		
         	$('status').addClassName('success').show();
         	$('status').update(message);
			setTimeout("$('status').style.display='none'",2000);

      	}
   	});		
}

function searchXboxUsers() {
	
	var firstname = $('firstname').getValue();
	var lastname = $('lastname').getValue();
	
	if (firstname.blank() || lastname.blank()) return false;
	
	new Ajax.Request('/ajax/usermanagement_ajax.php',
   	{	
        onCreate: function () {
      	$('searching').show();	
	    $('searchbutton').disabled = true;
	    $('searchbutton').addClassName('buttondisable').show();
       	},
     	onComplete: function() {
     	$('searching').hide();
   	  	$('searchbutton').disabled = false;
   	  	$('searchbutton').removeClassName('buttondisable').show();
      	},  			
      	method: 'POST',
      	parameters: {action: 'searchxboxusers',
      				 firstname: firstname,
      				 lastname: lastname
      				 },
      	failure:'errors',
      	insertion: Insertion.Top,
      	onSuccess:function(transport) {
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;  
 
         		
         	$('searchxboxresults').show();
         	$('searchxboxresults').update(html);
		

      	}
   	});		
}

function submitRateaRef(gameid) {
	
	var formdata = $('theform_' + gameid).serialize();
	
	new Ajax.Request('/ajax/rar_ajax.php',
   	{	
        onCreate: function () {
		    $('submitbutton').disabled = true;
		    $('submitbutton').addClassName('buttondisable').show();
		    $('status').removeClassName('failure').show();
		    $('status').removeClassName('success').show();
       	},
     	onComplete: function() {
	   	  	$('submitbutton').disabled = false;
	   	  	$('submitbutton').removeClassName('buttondisable').show();
      	},  			
      	method: 'POST',
		parameters: formdata,
      	failure:'errors',
      	insertion: Insertion.Top,
      	onSuccess:function(transport) {
         	var json = transport.responseText.evalJSON(true);
 			
         	if (json.errormessage) {
         		$('status').addClassName('failure').show();
         		$('status').update(json.errormessage);
         	} else {
         		$('game_' + json.gameid).update(json.successhtml);
         		
         	}

      	}
   	});		
   		
}

